﻿// 项目：	Guan.CMS.Web - Guan.CMS
// 文件名：	ToSelectListItemsHelper.cs
// 
// 修改时间：2013-03-06 19:49
// 修改人：	Cooclsee

using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Guan.CMS.Model.Entities;

namespace Guan.CMS.Web.Helpers
{
    public static class ToSelectListItemsHelper
    {
        public static IEnumerable<SelectListItem> ToSelectListItems(this IEnumerable<ArticleCategory> categories, int selectId)
        {
            var list = new List<SelectListItem> {new SelectListItem() {Text = string.Empty, Value = string.Empty}};
            var result =
                categories.OrderBy(c => c.Name)
                          .Select(
                              c =>
                              new SelectListItem()
                              {
                                  Selected = (c.Id == selectId),
                                  Text = c.Name,
                                  Value = c.Id.ToString()
                              });
            list.AddRange(result);
            return list;
        }
    }
}